<template>
  <view class="submit-sign">
    <uni-popup ref="popup" background-color="#fff" :is-mask-click="false" @change="change">
      <view class="popup-content">
        <view class="top">
          <text class="close" @click="close">取消</text>
          <text class="title">验收签字</text>
          <text class="submit" @click="submit">确定</text>
        </view>
        <view class="sign-content">
          <SignName ref="signName" />
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
  import SignName from './SignName';
  
  export default {
    name: 'SubmitSign',
    components: {
      SignName,
    },
    props: {},
    data() {
      return {};
    },
    mounted() {
      this.$nextTick(() => {
        this.$refs.popup.open('bottom');
      });
    },
    created() {
    },
    methods: {
      async submit() {
        const signName = this.$refs.signName[ 0 ] || this.$refs.signName;
        const { file } = await signName.getFile();
        this.$emit('submit', { file });
      },
      close() {
        this.$refs.popup.close();
      },
      change(e) {
        if (!e.show) {
          setTimeout(() => {
            this.$emit('close');
          }, 1000);
        }
        console.log(e);
      },
    },
  };
</script>

<style lang="less" scoped>
  .submit-sign {
    &, * {
      box-sizing: border-box;
    }
    .popup-content {
      height: 50vh;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      .top {
        display: flex;
        justify-content: space-between;
        text {
          display: block;
          font-size: 16px;
          padding: 15px;
          line-height: 1;
          cursor: pointer;
          &.title {
            color: black;
          }
          &.close {
            color: #cccccc;
          }
          &.submit {
            color: #007aff;
          }
        }
      }
      .sign-content {
        border-top: 1px solid #cccccc;
        flex: 1;
        overflow: hidden;
      }
    }
  }
</style>
